load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library")
load("@rules_cc//cc:cc_library.bzl", "cc_library")

package(
    # copybara:uncomment default_applicable_licenses = ["//tensorflow:license"],
    default_visibility = [":friends"],
    licenses = ["notice"],
)

package_group(
    name = "friends",
    includes = [
        "//xla:friends",
    ],
)

gentbl_cc_library(
    name = "passes_inc_gen",
    tbl_outs = {
        "passes.h.inc": [
            "-gen-pass-decls",
            "-name=TritonXlaTransforms",
        ],
    },
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "passes.td",
    visibility = ["//visibility:private"],
    deps = ["@llvm-project//mlir:PassBaseTdFiles"],
)

cc_library(
    name = "passes",
    srcs = [
        "arith_fp8_conversion_to_triton.cc",
        "extract_tma_info_pass.cc",
        "generalize_kernel_signature.cc",
        "int4_passes.cc",
        "round_f32_to_tf32_for_tf32_dot_pass.cc",
        "stablehlo_lower_to_triton.cc",
        "tensor_lower_to_triton.cc",
        "triton_xla_convert_unsupported_types.cc",
        "triton_xla_extract_insert_to_triton_pass.cc",
        "triton_xla_fold_transpose_pass.cc",
        "triton_xla_lower_atomics_pass.cc",
        "triton_xla_lower_block_barrier_pass.cc",
        "triton_xla_lower_get_tid_pass.cc",
        "triton_xla_lower_remote_access_pass.cc",
        "triton_xla_lower_xtile_pass.cc",
        "triton_xla_math_to_libdevice.cc",
        "triton_xla_squeeze_dims_pass.cc",
        "triton_xla_unswitch_loops_pass.cc",
        "xtile_lower_to_triton.cc",
    ],
    hdrs = ["passes.h"],
    deps = [
        ":passes_inc_gen",
        "//xla:permutation_util",
        "//xla:util",
        "//xla:xla_data_proto_cc",
        "//xla/backends/gpu/codegen/triton:dot_algorithms",
        "//xla/backends/gpu/codegen/triton:emitter_helpers",
        "//xla/backends/gpu/codegen/triton/ir:triton_xla",
        "//xla/codegen/emitters/ir:xla",
        "//xla/codegen/xtile/ir:xtile",
        "//xla/hlo/translate/mhlo_to_hlo:attribute_exporter",
        "//xla/service:algorithm_util",
        "//xla/service/gpu:target_util",
        "//xla/service/llvm_ir:llvm_util",
        "//xla/stream_executor/gpu:collective_kernel_metadata",
        "//xla/stream_executor/gpu:tma_metadata",
        "//xla/tsl/platform:errors",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log",
        "@com_google_absl//absl/log:check",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_absl//absl/types:span",
        "@llvm-project//llvm:Support",
        "@llvm-project//llvm:TargetParser",
        "@llvm-project//mlir:Analysis",
        "@llvm-project//mlir:ArithDialect",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:FunctionInterfaces",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:InliningUtils",
        "@llvm-project//mlir:LLVMCommonConversion",
        "@llvm-project//mlir:LLVMDialect",
        "@llvm-project//mlir:MathDialect",
        "@llvm-project//mlir:MemRefDialect",
        "@llvm-project//mlir:NVVMDialect",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:Rewrite",
        "@llvm-project//mlir:SCFDialect",
        "@llvm-project//mlir:SCFTransforms",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TensorDialect",
        "@llvm-project//mlir:TransformUtils",
        "@stablehlo//:stablehlo_ops",
        "@triton//:TritonDialects",
        "@tsl//tsl/platform:tensor_float_32_hdr_lib",
    ],
)
